﻿using System;
using System.Collections.Generic;
using System.Windows;
using Yxinmt.Entity;

namespace 智慧无纸化会议客户端软件
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();

            InitForm();

            Closed += MainWindow_Closed;
        }

        private void MainWindow_Closed(object sender, EventArgs e)
        {
            if (EventAction.ExitAction != null) EventAction.ExitAction();
        }

        public void AddChildControl(UIElement obj)
        {
            this.viewbox1.Child = obj;
        }

        public void InitExitAction(Action action)
        {
             EventAction.ExitAction = action;
        }

        private void InitForm()
        {
            try
            {
                new Yxinmt.Windows.Meeting.MainWindow2();
                Yxinmt.Windows.MainWindow mw = new Yxinmt.Windows.MainWindow(this, "Index", typeof(DefaultWindow), getClientConfig(), (a) =>
                {
                    InitExitAction(a);
                });
                this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
                this.ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip;
                this.Width = 1600;
                this.Height = 900;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息");
            }
        }

        Dictionary<string,object> getClientConfig()
        {
            var config = Yxinmt.Utility.Common.GetConfig<Dictionary<string,object>>("clientConfig");
            if (config == null)
            {
                config = new Dictionary<string, object>();
                config["Serial"] = Yxinmt.Utility.Common.ToBase64String(Yxinmt.Utility.LocalUniqueId.GetValue());
                config["Mac"] = Yxinmt.Utility.Common.GetMacAddress();

                Yxinmt.Utility.Common.SaveConfig<Dictionary<string, object>>("clientConfig", config);
            }
            return config;
        }
    }
}
